package twitter;

import java.math.BigInteger;

//you can also use imports, for example:
//import java.math.*;
class Solution {
	public static int solution(int[][] A) {
		// write your code in Java SE 7
        if(A == null||A.length == 0){
			return 0;
		}
		int result = 0;
		//compute row sum and column sum.
		
		BigInteger[] sumRow = new BigInteger[A.length];
		BigInteger[] sumCol = new BigInteger[A[0].length];
		BigInteger sum = BigInteger.ZERO;
		for(int i = 0; i < sumRow.length; ++i){
			for(int j = 0; j < sumCol.length; ++j){
				sum = sum.add(BigInteger.valueOf(A[i][j]));
			}
			sumRow[i] = sum;
		}
		sum = BigInteger.ZERO;
		for(int j = 0; j != sumCol.length;++j){
			for(int i = 0; i != sumRow.length;++i){
				sum = sum.add(BigInteger.valueOf(A[i][j]));
			}
			sumCol[j] = sum;
		}
		
		//check
		for(int i = 0; i < sumRow.length; ++i){
			BigInteger before = BigInteger.ZERO;
			if(i != 0){
				before = sumRow[i - 1];
			}
			BigInteger after = sumRow[sumRow.length - 1].subtract(sumRow[i]);
			if(before.equals(after)){
				++result;
			}
		}
		int equal = 0;
		for(int i = 0; i != sumCol.length; ++i){
			BigInteger before = BigInteger.ZERO;
			if(i != 0){
				before = sumCol[i - 1];
			}
			BigInteger after = sumCol[sumCol.length - 1].subtract(sumCol[i]);// - sumCol[i];
			if (before.equals(after)) {
				++equal;
			}
		}
		return result*equal;
	}
	
	
	public static void main(String[] args){
		int[][] A = {{2147483647,2147483647},{-2147483647,2147483647},{0,2147483647}};
		System.out.println(solution(A));
		System.out.println((long)Integer.MAX_VALUE*1000000);
	}
}
